package net.cyl.service.impl;

import net.cyl.manager.ProductManager;
import net.cyl.model.ProductDO;
import net.cyl.mapper.ProductMapper;
import net.cyl.service.ProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.cyl.vo.ProductVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 曹玉林
 * @since 2025-05-20
 */
@Service
public class ProductServiceImpl  implements ProductService {
    @Autowired
    private ProductManager productManager;
    @Override
    public List<ProductVO> list() {
        List<ProductDO> productDOS = productManager.list();
        return productDOS.stream().map(this::convert).collect(Collectors.toList());
    }

    @Override
    public ProductVO detail(Long productId) {
        ProductDO productDO = productManager.findById(productId);
        return convert(productDO);
    }

    private ProductVO convert(ProductDO productDO) {
                ProductVO productVO = new ProductVO();
                BeanUtils.copyProperties(productDO, productVO);
                return productVO;
    }
}
